{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #采集果实"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #array"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #数组"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: getMinimumTime"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #采集果实"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "欢迎各位勇者来到力扣新手村，本次训练内容为「采集果实」。\n",
    "\n",
    "在新手村中，各位勇者需要采集一些果实来制作药剂。`time[i]` 表示勇者每次采集 `1～limit` 颗第 `i` 种类型的果实需要的时间（即每次最多可以采集 `limit` 颗果实）。\n",
    "\n",
    "当前勇者需要完成「采集若干批果实」的任务， `fruits[j] = [type, num]` 表示第 `j` 批需要采集 `num` 颗 `type` 类型的果实。采集规则如下：\n",
    "- 按 `fruits` 给定的顺序**依次**采集每一批次\n",
    "- 采集完当前批次的果实才能开始采集下一批次\n",
    "- 勇者完成当前批次的采集后将**清空背包**（即多余的果实将清空）\n",
    "\n",
    "请计算并返回勇者完成采集任务最少需要的时间。\n",
    "\n",
    "\n",
    "**示例 1：**\n",
    ">输入：`time = [2,3,2], fruits = [[0,2],[1,4],[2,1]], limit = 3`\n",
    ">\n",
    ">输出：`10`\n",
    ">\n",
    ">解释：\n",
    ">由于单次最多采集 3 颗\n",
    ">第 0 批需要采集 2 颗第 0 类型果实，需要采集 1 次，耗时为 2\\*1=2\n",
    ">第 1 批需要采集 4 颗第 1 类型果实，需要采集 2 次，耗时为 3\\*2=6\n",
    ">第 2 批需要采集 1 颗第 2 类型果实，需要采集 1 次，耗时为 2\\*1=2\n",
    ">返回总耗时 2+6+2=10\n",
    "\n",
    "**示例 2：**\n",
    ">输入：`time = [1], fruits = [[0,3],[0,5]], limit = 2`\n",
    ">\n",
    ">输出：`5`\n",
    ">\n",
    ">解释：\n",
    ">由于单次最多采集 2 颗\n",
    ">第 0 批需要采集 3 颗第 0 类型果实，需要采集 2 次，耗时为 1\\*2=2\n",
    ">第 1 批需要采集 5 颗第 0 类型果实，需要采集 3 次，耗时为 1\\*3=3\n",
    ">需按照顺序依次采集，返回 2+3=5\n",
    "\n",
    "**提示：**\n",
    "- `1 <= time.length <= 100`\n",
    "- `1 <= time[i] <= 100`\n",
    "- `1 <= fruits.length <= 10^3`\n",
    "- `0 <= fruits[i][0] < time.length`\n",
    "- `1 <= fruits[i][1] < 10^3`\n",
    "- `1 <= limit <= 100`"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [PTXy4P](https://leetcode.cn/problems/PTXy4P/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [PTXy4P](https://leetcode.cn/problems/PTXy4P/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['[2,3,2]\\n[[0,2],[1,4],[2,1]]\\n3', '[1]\\n[[0,3],[0,5]]\\n2']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        m = {}\n",
    "        for item in fruits:\n",
    "            tp = item[0]\n",
    "            if tp not in m.keys():\n",
    "                m[tp] = [item[1]]\n",
    "            else:\n",
    "                m[tp].append(item[1])\n",
    "        ans = 0\n",
    "        for i, cost in enumerate(time):\n",
    "            if i not in m.keys():\n",
    "                continue\n",
    "            nums = m[i]\n",
    "            for num in nums:\n",
    "                ans += (num // limit) * cost\n",
    "                if num % limit != 0:\n",
    "                    ans += cost\n",
    "        return ans\n",
    "                    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum((cnt + limit - 1) // limit * time[i] for i, cnt in fruits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        res = 0\n",
    "        for i in range(len(fruits)):\n",
    "            if fruits[i][1] % limit == 0:\n",
    "                res += ((fruits[i][1] // limit) * time[fruits[i][0]])\n",
    "            else:\n",
    "                res += ((fruits[i][1] // limit + 1) * time[fruits[i][0]])\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum((num + limit - 1) // limit * time[t] for t, num in fruits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans=0\n",
    "        for i in range(len(fruits)):\n",
    "            ans+=time[fruits[i][0]]*(fruits[i][1]//limit)\n",
    "            if fruits[i][1]%limit!=0:\n",
    "                ans+=time[fruits[i][0]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        import math\n",
    "        res = 0\n",
    "        for t,n in fruits:\n",
    "            res += time[t] * math.ceil(n/limit)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        res = 0\n",
    "        for t, n in fruits:\n",
    "            res += math.ceil(n / limit) * time[t]\n",
    "\n",
    "\n",
    "        return res\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        res = 0\n",
    "        for i, v in enumerate(fruits):\n",
    "            res += time[v[0]] * ceil(v[1] / limit)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum((cnt + limit - 1) // limit * time[i] for i, cnt in fruits)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        times =  0\n",
    "        for i,j in fruits:\n",
    "            if j != 0:\n",
    "                c = ceil(j/limit)\n",
    "                times += c*time[i]\n",
    "        return times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        result = 0\n",
    "        for fruit in fruits:\n",
    "            result = result + time[fruit[0]] * math.ceil(fruit[1] / limit)\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        cost = 0\n",
    "        for i in range(len(fruits)):\n",
    "            n = ceil(fruits[i][1]/limit)\n",
    "            idx = fruits[i][0]\n",
    "            cost+=time[idx]*n\n",
    "        return cost"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans = 0\n",
    "        n = len(fruits)\n",
    "        for i in range(n):\n",
    "            type, num = fruits[i][0], fruits[i][1]\n",
    "            times = ceil(num/limit)\n",
    "            ans += times * time[type]\n",
    "\n",
    "        return ans "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        # time[i] 表示采集1-limint颗第i种类型的果实需要的时间；\n",
    "        # fruits[j] = [type, num], 表示第j批需要采集num颗type类型的果实；\n",
    "        # limit, 表示每次最多采集limit颗产品;\n",
    "        # 采集规则：1、按照fruits给定的顺序采集；2、采集完当前批次才能采集下一批次；3、\n",
    "        # 请返回完成采集任务最少需要的时间\n",
    "        n = len(fruits)\n",
    "        ans = 0\n",
    "        for i in range(n):\n",
    "            tp, num = fruits[i]\n",
    "            t = num / limit if num % limit == 0 else (num // limit) + 1# 计算采集次数\n",
    "            ans += time[tp] * t #计算需要的时间\n",
    "        return int(ans)\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "         ans=0\n",
    "         each=0\n",
    "         for i in range (len(fruits)):\n",
    "            j=fruits[i][1]\n",
    "            if j<=limit:\n",
    "                each=time[fruits[i][0]]*1\n",
    "            elif j>limit:\n",
    "                if j%limit==0:\n",
    "                    each=time[fruits[i][0]]*(j//limit)\n",
    "                else:\n",
    "                    each=time[fruits[i][0]]*(j//limit+1)\n",
    "\n",
    "            ans+=each\n",
    "         return ans\n",
    "                \n",
    "\n",
    "            \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans = 0\n",
    "        for fruit in fruits:\n",
    "            type_ = fruit[0]\n",
    "            num = fruit[1]\n",
    "            tim = time[type_] * math.ceil(num/limit)\n",
    "            ans += tim\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans = 0\n",
    "        for ind, f in enumerate(fruits):\n",
    "            typ, num = f[0], f[1]\n",
    "            ans += math.ceil(num / limit) * time[typ]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        import math\n",
    "        ans = 0\n",
    "        for item in fruits:\n",
    "            ans += (math.ceil(item[1]/limit)) * time[item[0]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans=0\n",
    "        for i,j in fruits:\n",
    "            ans+=math.ceil(j/limit)*time[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum((cnt + limit - 1) // limit * time[i] for i, cnt in fruits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        res = 0\n",
    "        for fruit in fruits:\n",
    "            timestamp = math.ceil(fruit[1] / limit)\n",
    "            res += timestamp * time[fruit[0]]\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans = 0 \n",
    "        for i, f in enumerate(fruits):\n",
    "            if f[1] % limit == 0:\n",
    "                ans += (f[1] // limit) * time[f[0]]\n",
    "            else:\n",
    "                ans += (f[1] // limit + 1) * time[f[0]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        # m = {}\n",
    "        # for item in fruits:\n",
    "        #     tp = item[0]\n",
    "        #     if tp not in m.keys():\n",
    "        #         m[tp] = [item[1]]\n",
    "        #     else:\n",
    "        #         m[tp].append(item[1])\n",
    "        # ans = 0\n",
    "        # for i, cost in enumerate(time):\n",
    "        #     if i not in m.keys():\n",
    "        #         continue\n",
    "        #     nums = m[i]\n",
    "        #     for num in nums:\n",
    "        #         ans += (num // limit) * cost\n",
    "        #         if num % limit != 0:\n",
    "        #             ans += cost\n",
    "        # return ans\n",
    "        ans = 0\n",
    "        for fruit in fruits:\n",
    "            tp = fruit[0]\n",
    "            ans += time[tp] * math.ceil(fruit[1]/limit)\n",
    "        return ans\n",
    "                    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum((cnt + limit - 1) // limit * time[i] for i, cnt in fruits)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans=0\n",
    "        for i in range(len(fruits)):\n",
    "            ans+=(fruits[i][1]//limit)*time[fruits[i][0]]\n",
    "            if fruits[i][1]%limit!=0:\n",
    "                ans+=time[fruits[i][0]]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum(time[f[0]]*math.ceil(f[1]/limit) for f in fruits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        s=0\n",
    "        for x,y in fruits:\n",
    "            if y<=limit:\n",
    "                s+=time[x]\n",
    "            else:\n",
    "                if y%limit==0:\n",
    "                    s+=(y//limit)*time[x]\n",
    "                else:\n",
    "\n",
    "                    s+=(y//limit+1)*time[x]\n",
    "        return s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        t = 0\n",
    "        for i in range(len(fruits)):\n",
    "            t += time[fruits[i][0]]*(math.ceil(fruits[i][1] / limit))\n",
    "        return t"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        # times = 0\n",
    "        # for i,k in fruits:\n",
    "        #    times += time[i] * ceil(k / limit)\n",
    "        # return times\n",
    "        return sum(time[i] * ceil(k / limit) for i,k in fruits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans = 0\n",
    "        for [i, j] in fruits:\n",
    "            # print(ans)\n",
    "            ans += (((j-1) // limit) + 1) * time[i]\n",
    "            # print(ans)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum((cnt + limit - 1) // limit * time[i] for i, cnt in fruits)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        w=limit-1\n",
    "        return sum([((n+w)//limit)*time[t] for (t,n) in fruits])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "            return sum([((n+limit-1)//limit)*time[t] for (t,n) in fruits])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        min_time = 0\n",
    "        for fruit, num in fruits:\n",
    "            num_ops = num // limit\n",
    "            if num % limit != 0:\n",
    "                num_ops += 1\n",
    "            min_time += time[fruit] * num_ops\n",
    "        return min_time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans = 0\n",
    "        for i, j in fruits:\n",
    "            tmp = 1\n",
    "            if j > limit:\n",
    "                tmp = j // limit if j % limit == 0 else j // limit + 1\n",
    "            ans += tmp * time[i]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum((x + limit - 1) // limit * time[i] for i, x in fruits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans =0\n",
    "        for x, y in fruits:\n",
    "            ans += (y + limit - 1) // limit * time[x]\n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum(time[fruits[i][0]] * ceil(fruits[i][1] / limit) for i in range(len(fruits)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans = 0\n",
    "        for ind,cnt in fruits:\n",
    "            t= 0 if cnt%limit==0 else 1\n",
    "            n = cnt//limit+t\n",
    "            ans += n*time[ind]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        result = 0\n",
    "        for fruit in fruits:\n",
    "            result = result + time[fruit[0]] * math.ceil(fruit[1] / limit)\n",
    "\n",
    "        return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "            return sum([((n+limit-1)//limit)*time[t] for (t,n) in fruits])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        res=0\n",
    "        nums=0\n",
    "        n=len(fruits)\n",
    "        for i in range(n):\n",
    "            fruit=fruits[i]\n",
    "            # times=(fruit[1]//limit)+1\n",
    "            type=fruit[0]\n",
    "            num=fruit[1]\n",
    "            t=math.ceil(num/limit)\n",
    "            nums=t*time[type]+nums\n",
    "           \n",
    "        return nums "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum([time[i] * ((j - 1) // limit + 1)for i,j in fruits])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import math\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time, fruits, limit):\n",
    "        total = 0\n",
    "        for i in fruits:\n",
    "            # print(math.ceil(i[1]/time[i[0]])*time[i[0]])\n",
    "            total = total + math.ceil(i[1]/limit)*time[i[0]]\n",
    "        return total\n",
    "\n",
    "# time = [2,3,2]\n",
    "# fruits = [[0,2],[1,4],[2,1]]\n",
    "# limit = 3\n",
    "# a = Solution()\n",
    "# print(a.getMinimumTime(time,fruits,limit))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "from math import ceil\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans=0\n",
    "        for t,num in fruits:\n",
    "            ans+=ceil(num/limit)*time[t]\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        import math\n",
    "        res = 0\n",
    "\n",
    "        for i in range(len(fruits)):\n",
    "            res += time[ fruits[i][0]] * math.ceil( fruits[i][1]/limit)\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        sum = 0\n",
    "        for type, num in fruits:\n",
    "            if num%limit!=0:\n",
    "                n = num//limit+1\n",
    "                sum+=n*time[type]\n",
    "            else:\n",
    "                n = num//limit\n",
    "                sum += n*time[type]\n",
    "        return sum"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum(time[f[0]]*math.ceil(f[1]/limit) for f in fruits)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        ans = 0\n",
    "        for type, num in fruits:\n",
    "            ans += time[type] * ((num + limit - 1) // limit)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum(ceil(num / limit) * time[tp] for tp, num in fruits)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def getMinimumTime(self, time: List[int], fruits: List[List[int]], limit: int) -> int:\n",
    "        return sum((cnt + limit - 1) // limit * time[i] for i, cnt in fruits)"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
